package com.yitongmao.core.network.httpclient;


import com.yitongmao.core.glide.ProgressListener;
import com.yitongmao.core.glide.ProgressResponseBody;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Response;

public class DownloadProgressInterceptor implements Interceptor {

    private ProgressListener progressListener;

    public DownloadProgressInterceptor(ProgressListener progressListener){
        this.progressListener = progressListener;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Response originalResponse = chain.proceed(chain.request());
        return originalResponse.newBuilder()
                .body(new ProgressResponseBody(originalResponse.body(), progressListener))
                .build();
    }
}
